<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itheima" uri="http://itheima.com/common/"%>
<%@ include file="/common/base.jsp"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
 <link rel="stylesheet" href="<%=path%>/css/pintuer.css">
<link rel="stylesheet" href="<%=path%>/css/admin.css">
<script src="<%=path%>/js/jquery.js"></script>
<script src="<%=path%>/js/pintuer.js"></script>
</head>
<body>
	<form method="post" action="" id="listform">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder">菜品列表</strong>
			</div>
			<div class="padding border-bottom">
				<ul class="search" style="padding-left:10px;">
					<li><a class="button border-main icon-plus-square-o"
						href="../vegetable/create.action" > 添加菜品</a></li>
						<form method="post" action="${pageContext.request.contextPath }/vegetable/list.action" >
					<li>搜索：</li>
					<li>
					<input type="text" placeholder="请输入菜品编号" name="vegetable_id"
						class="input" value="${vegetable_id }" id="vegetable_id"
						style="width:250px; line-height:17px;display:inline-block" />
					<input type="text" placeholder="请输入菜品名称" name="vegetable_name"
						class="input" value="${vegetable_name }" id="vegetable_name"
						style="width:250px; line-height:17px;display:inline-block" /> 
						<input type="text" placeholder="请输入菜品价格" name="price"
						class="input" value="${price }" id="price"
						style="width:250px; line-height:17px;display:inline-block" />
						<button type="submit" class="button border-main icon-search"> 
						 搜索</button></li>
						 </form>
				</ul>
			</div>
			<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<!-- /.panel-heading -->
			<table class="table table-hover text-center">
			<thead>
				<tr>
					<th>菜品编号</th>
					<th>菜品名称</th>
					<th>菜品描述</th>
					<th>价钱</th>
					<th>操作</th>
				</tr>
				</thead>
	             <tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.vegetable_id}</td>
									<td>${row.vegetable_name}</td>
									<td>${row.describes}</td>
									<td>${row.price}</td>		
				   <td><div class="button-group">
							<a class="button border-main"
								href="../vegetable/getVegetableById.action?vegetable_id=${row.vegetable_id}" onclick= "editVegetable(${row.vegetable_id})"><span
								class="icon-edit"></span> 修改</a> <a class="button border-red"
								href="../vegetable/delete.action?id=${row.vegetable_id}" onclick="deleteVegetable(${row.vegetable_id})"><span
								class="icon-trash-o"></span> 删除</a>
						</div></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>	
			
					<div class="col-md-12 text-right">
						<itheima:page url="${pageContext.request.contextPath }/vegetable/list.action" />
					</div>
		<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
		</div>
	</form>
	<script>
		// 通过id获取修改的客户信息
	function editUser(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>vegetable/getVegetableById.action",
	        data:{"":id},
	        success:function(data) {
	            $("#vegetable_id").val(data.vegetable_id);
	            $("#vegetable_name").val(data.vegetable_name);
	            $("#describe").val(data.describe)
	            $("#price").val(data.price) 
	        }
	    });
	}
	   // 执行修改客户操作
	function updateVegetable() {
		$.post("<%=basePath%>vegetable/updateVegetable.action",$("#listform").serialize(),function(data){
			if(data =="OK"){
				alert("客户信息更新成功！");
				window.location.reload();
			}else{
				alert("客户信息更新失败！");
				window.location.reload();
			}
		});
	}
	
  function query(){
	  $("#listform").submit();
  }
  // 删除客户
	function deleteVegetable(id) {
	    if(confirm('确实要删除该客户吗?')) {
	$.post("<%=basePath%>vegetable/delete.action",{"vegetable_id":id},
	function(data){
	            if(data =="OK"){
	                alert("客户删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除客户失败！");
	                window.location.reload();
	            }
	        });
	    }
</script>
</body>
</html>
